module;
#include <vector>
#include <iostream>
#include <functional>
export module Code_22_1_0;

//[1]
//template<typename F>
//void forUpTo(int n, F f) 
//{
//    for (int i = 0; i != n; ++i)
//    {
//        f(i); // call passed function f for i
//    }
//}
//[1]
void printInt(int i)
{
    std::cout << i << ' ';
}

//[2]
void forUpTo(int n, std::function<void(int)> f)
{
    for (int i = 0; i != n; ++i)
    {
        f(i); // call passed function f for i
    }
}
export
namespace Code_22_1_0 {

    void run()
    {
        //[1]
        std::vector<int> values;
		// insert values from 0 to 4:
		forUpTo(5, [&values](int i) {
			values.push_back(i);
			});

        // print elements:
        forUpTo(5, printInt); // prints 0 1 2 3 4

        std::cout << '\n';
    }
}

